#include <stdio.h>
#include "ShmBlock.h"

CShmBlock::CShmBlock()
{
    m_pBuf = nullptr;
    m_nLen = 0;
    m_nCur = 0;
}

CShmBlock::~CShmBlock()
{
}

void CShmBlock::Init(void *pBuf, uint64_t nLen)
{
    m_pBuf = pBuf;
    m_nLen = nLen;
}

void *CShmBlock::Alloc(int iLen)
{
    void *ptr = nullptr;

    if (0 >= iLen)
    {
        printf("CShmBlock::Alloc param error, iLen=%d\n", iLen);
        return nullptr;
    }

    if (m_nCur + iLen > m_nLen)
    {
        printf("CShmBlock::Alloc param error, (m_nCur + iLen > m_nLen)\n");
        return nullptr;
    }

    ptr = (char *)m_pBuf + m_nCur;
    m_nCur += iLen;

    return ptr;
}

void CShmBlock::Free(void *ptr)
{
}